package utils;

import enums.PayErrorEnum;
import exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@Slf4j
public class AssertUtils {

	private static PayErrorEnum errorLog;

	public static void notNull(Object obj) {
		if (obj == null) {
			errorLog = PayErrorEnum.PAY_PARAM_IS_INVALID;
			log.warn(errorLog.getMessageCN());
			throw new CommonException(errorLog.getCode(), errorLog.getMessageCN());
		}
	}

	public static void notNull(Object obj, String msg) {
		if (obj == null) {
			log.warn(msg);
			throw new CommonException(PayErrorEnum.PAY_PARAM_IS_INVALID.getCode(), msg);
		}
	}

	public static void notBlank(String obj) {
		if (StringUtils.isBlank(obj)) {
			errorLog = PayErrorEnum.PAY_PARAM_IS_BLANK;
			log.warn(errorLog.getMessageCN());
			throw new CommonException(errorLog.getCode(), errorLog.getMessageCN());
		}
	}

	public static void notBlank(String obj, String msg) {
		if (StringUtils.isBlank(obj)) {
			log.warn(msg);
			throw new CommonException(PayErrorEnum.PAY_PARAM_IS_BLANK.getCode(), msg);
		}
	}

	public static void notTrue(boolean result, String msg) {
		if (!result) {
			log.warn(msg);
			throw new CommonException(PayErrorEnum.PAY_PARAM_IS_BLANK.getCode(), msg);
		}
	}

	public static void notEqual(Object obj1, String obj2) {
		if (!Objects.equals(obj1,obj2)) {
			errorLog = PayErrorEnum.PAY_PARAM_NOT_EQUALS;
			log.warn(errorLog.getMessageCN());
			throw new CommonException(PayErrorEnum.PAY_PARAM_NOT_EQUALS.getCode(), errorLog.getMessageCN());
		}
	}

	public static void notEqual(Object obj1, String obj2,String msg) {
		if (!Objects.equals(obj1,obj2)) {
			log.warn(msg);
			throw new CommonException(PayErrorEnum.PAY_PARAM_IS_INVALID.getCode(), msg);
		}
	}
}